package com.winit.generator.handler.impl;

import com.winit.generator.Constants;
import com.winit.generator.config.Configuration;
import com.winit.generator.handler.BaseHandler;
import com.winit.generator.model.EntityInfo;

import java.io.File;

public class CreateHandler extends BaseHandler<EntityInfo> {

    public CreateHandler(String ftlName, EntityInfo info){
        this.ftlName = ftlName;
        this.info = info;
        this.savePath = Configuration.getString("base.baseDir") + File.separator
                        + Configuration.getString("filter.path") + File.separator + info.getCreateName()
                        + Constants.FILE_SUFFIX_JAVA;

    }

    @Override
    public void combileParams(EntityInfo entityInfo) {
        this.param.put("packageStr", entityInfo.getEntityPackage());
        this.param.put("filterPackageStr", entityInfo.getFilterPackage());
        StringBuilder sb = new StringBuilder();
        for (String str : entityInfo.getImports()) {
            sb.append("import ").append(str).append(";\r\n");
        }
        this.param.put("importStr", sb.toString());
        this.param.put("entityDesc", entityInfo.getEntityDesc());
        this.param.put("className", entityInfo.getClassName());
        this.param.put("filterName", entityInfo.getFilterName());
        this.param.put("createName", entityInfo.getCreateName());
    }
}
